package com.timebank.score.controller;

import com.timebank.common.core.web.controller.BaseController;
import com.timebank.common.core.web.page.TableDataInfo;
import com.timebank.common.core.web.pojo.AjaxResult;
import com.timebank.common.security.annotation.RequiresLogin;
import com.timebank.score.pojo.entity.Prize;
import com.timebank.score.service.PrizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 奖品 控制层
 * @author shiliuyinzhen
 */
@RestController
@RequestMapping("/prize")
@Api(tags = "奖品相关接口")
public class PrizeController extends BaseController {

    @Resource
    private PrizeService prizeService;

    /**
     * 获取奖品列表
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("获取奖品列表")
    public TableDataInfo getPrizeList(){
        startPage();
        List<Prize> list = prizeService.getPrizeList();
        return getDataTable(list);
    }

    /**
     * 新增奖品
     * @param prize
     * @return
     */
    @RequiresLogin
    @PostMapping
    @ApiOperation("新增奖品")
    public AjaxResult addPrize(@RequestBody Prize prize){
        return prizeService.addPrize(prize);
    }

    /**
     * 批量删除奖品
     * @param prizeIds
     * @return
     */
    @RequiresLogin
    @DeleteMapping("/{prizeIds}")
    @ApiOperation("批量删除奖品")
    public AjaxResult batchDeletePrize(@PathVariable("prizeIds") Long[] prizeIds){
        return prizeService.batchDeletePrize(prizeIds);
    }

    /**
     * 修改奖品信息
     * @param prize
     * @return
     */
    @RequiresLogin
    @PutMapping("/{prizeId}")
    @ApiOperation("修改奖品信息")
    public AjaxResult updatePrize( @PathVariable("prizeId") Long prizeId
            , @RequestBody Prize prize){
        prize.setId(prizeId);
        return prizeService.updatePrize(prize);
    }
}
